package com.dg.river.core.util;

import android.content.Context;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by hy on 2018/10/16
 * Description : 网络工具类
 */
public class NetUtils {
    /**
     * 判断是否有网络
     *
     * @param mContext
     * @return
     */
    public static boolean isNetworkAvailable(Context mContext) {
        ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager == null) {
            return false;
        } else {
            NetworkInfo[] networkInfo = connectivityManager.getAllNetworkInfo();
            if (networkInfo != null && networkInfo.length > 0) {
                for (int i = 0; i < networkInfo.length; i++) {
                    if (networkInfo[i].getState() == NetworkInfo.State.CONNECTED) {
                        return true;
                    }
                }
            }
        }
        return false;
    }


    /**
     * 判断是否开启WIFI定位
     *
     * @param context
     * @return
     */
    public static boolean isWifiNetwrokType(Context context) {
        /**
         * 获取的是位置服务
         */
        String serviceString = Context.LOCATION_SERVICE;
        /**
         * 调用getSystemService()方法来获取LocationManager对象
         */
        LocationManager locationManager = (LocationManager) context.getSystemService(serviceString);
        /**
         * 如果没有开启位置源，转到‘设置’-‘位置和安全’里勾选使用无线网络，来激活NETWORK_PROVIDER 或 GPS_PROVIDER
         */
        if (!locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 判断是否开启GPS定位
     *
     * @param context
     * @return
     */
    public static boolean isGPSNetwrokType(Context context) {
        /**
         * 获取的是位置服务
         */
        String serviceString = Context.LOCATION_SERVICE;
        /**
         * 调用getSystemService()方法来获取LocationManager对象
         */
        LocationManager locationManager = (LocationManager) context.getSystemService(serviceString);//
        /**
         * 如果没有开启位置源，转到‘设置’-‘位置和安全’里勾选使用无线网络，来激活NETWORK_PROVIDER 或 GPS_PROVIDER
         */
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 未开启手机定位
     *
     * @param context
     */
    public static void isNoAPPDialog(final Context context) {

    }
}
